﻿using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Text;

public class FileOperation : MonoBehaviour {
    public FileOperation() { }
    public  string pathUnity = "E:/";
	
    public  string getPath(string FileName){
        string path = "";
        path = pathUnity + FileName;
        return path;
    }
    public string checkFile(string FileName)
    {
        string path = getPath(FileName);
        if (!File.Exists(path))
        {
            FileStream file = File.Create(path);
        }
        return path;
    }
    public void sdfsdf()
    {

    }
    public void CreateFile(string FileName)
    {
        checkFile(FileName);
    }

    public  void WriteFile(string FileName) {
        string path = checkFile(FileName);
      //  File.WriteAllText(path,"noi dung ghi");
        //Pass the filepath and filename to the StreamWriter Constructor
        StreamWriter sw = new StreamWriter(path);

        //Write a line of text
        sw.WriteLine("Hello World!!");

        //Write a second line of text
        sw.WriteLine("From the StreamWriter class");

        //Close the file
        sw.Close();
    }
    public  void LoadFile(string FileName) {
        string line;
        string path = checkFile(FileName);
// read line
        //StreamReader sr = new StreamReader(path);
        
        //line = sr.ReadLine();
        //UnityEditor.EditorUtility.DisplayDialog("test", line, "ok");
        //while (line != null)
        //{
           
        //    //write the lie to console window
        //    Console.WriteLine(line);
        //    Debug.Log(line);
        //    //Read the next line
        //    line = sr.ReadLine();
        //}
       //  sr.Close()
  // read all
        StringBuilder sbOutput = new StringBuilder();
        //-------------read file

        using (StreamReader streamReaderOutPut = new StreamReader(path))
        {
            sbOutput.Append(streamReaderOutPut.ReadToEnd());
        } ;
       
        Console.ReadLine();
    }
}